<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <cpn :cmovies="movies" v-bind:cmessage="message"></cpn>
</div>

<template id="cpn">
    <div>
        <h2>{{cmovies}}</h2>
        <ul>
            <li v-for="(item, index) in cmovies">{{index + 1}} :: {{item}}</li>
        </ul>
        <h2>{{cmessage}}</h2>
    </div>
</template>

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>

    // 官网介绍：https://cn.vuejs.org/v2/guide/components-props.html#Prop-%E9%AA%8C%E8%AF%81
    const cpn = {
        // 1.props是数组形式
        // props: ['cmovies', 'cmessage'],
        // 2.props是对象形式
        props: {
            // 类型限制
            // cmovies: Array,
            // cmessage: String,

            // 提供一些默认值
            cmessage: {
                type: String,
                default: 'hello',
                required: true
            },
            // 类型是对象或者数组是，默认值必须是一个函数
            cmovies: {
                type: Array,
                default() {
                    return ['默认']
                }
            }
        },
        data() {
            return {}
        },
        methods: {

        },
        template: '#cpn'
    }

    const app = new Vue({
        el: '#app',
        data: {
            message: 'simplelu',
            movies: ['kai', '恺臻']
        },
        components: {
            cpn
        }
    })
</script>
</body>
</html>